// ===================================
// 修复后的 sdf.h 关键部分
// ===================================

#ifndef __SDF_H
#define __SDF_H

// 引入 GMSSL 库的头文件
#include <gmssl/sm3.h>
#include <gmssl/sm2.h> // 需要用到 SM2 相关的结构

// --- 1. 基础类型定义 (必须补齐) ---
typedef unsigned char BYTE;
typedef unsigned char CHAR;
typedef int LONG;
typedef unsigned int ULONG;
typedef unsigned int FLAGS;
typedef CHAR * LPSTR;
typedef void * HANDLE;

// --- 2. 算法标识符和错误码 (必须补齐) ---
#define SGD_SM3 0x00000004
#define SDR_OK 0x00000000
#define SDR_BASE 0x01000000
#define SDR_COMMFAIL SDR_BASE + 0x00000003
#define SDR_ALGNOTSUPPORT SDR_BASE + 0x00000009
#define SDR_STEPERR SDR_BASE + 0x00000010
#define SDR_INARGERR SDR_BASE + 0x0000001D
#define SDR_OUTARGERR SDR_BASE + 0x0000001E


// --- 3. 结构体定义 (必须补齐) ---
// 设备信息 (DEVICEINFO 结构体)
typedef struct DeviceInfo_st{
    CHAR IssuerName[40];
    CHAR DeviceName[16];
    CHAR DeviceSerial[16];
    ULONG DeviceVersion;
    ULONG StandardVersion;
    ULONG AsymAlgAbility[2];
    ULONG SymAlgAbility;
    ULONG HashAlgAbility;
    ULONG BufferSize;
}DEVICEINFO;

// ECC 结构体
#define ECCref_MAX_BITS 512
#define ECCref_MAX_LEN ((ECCref_MAX_BITS + 7) / 8)

typedef struct ECCrefPublicKey_st
{
    ULONG bits;
    BYTE x[ECCref_MAX_LEN];
    BYTE y[ECCref_MAX_LEN];
} ECCrefPublicKey;

// ECCrefPrivateKey 结构体 (SM3 不用，但为完整性保留)
typedef struct ECCrefPrivateKey_st
{
    ULONG bits;
    BYTE K[ECCref_MAX_LEN];
} ECCrefPrivateKey;


// --- 4. 函数声明 (保持不变) ---
LONG SDF_OpenDevice(HANDLE * phDeviceHandle);
LONG SDF_CloseDevice(HANDLE hDeviceHandle);
LONG SDF_GetDeviceInfo(HANDLE hSessionHandle, DEVICEINFO *pstDeviceInfo);

LONG SDF_HashInit(HANDLE hSessionHandle, ULONG uiAlgID, ECCrefPublicKey *pucPublicKey, BYTE *pucID, ULONG uiIDLength);
LONG SDF_HashUpdate(HANDLE hSessionHandle, BYTE *pucData, ULONG uiDataLength);
LONG SDF_HashFinal(HANDLE hSessionHandle, BYTE *pucHash, ULONG *puiHashLength);

#endif
